package com.moon.admin.sys.service;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moon.admin.sys.entity.SysDeptEntity;
import com.moon.admin.sys.entity.SysPostEntity;
import com.moon.admin.sys.mapper.SysPostMapper;

/**
 * 岗位 服务层实现
 * 
 * @author ninglong
 * @date Mon Jun 24 10:22:26 CST 2019
 */
@Service
public class SysPostService extends ServiceImpl<SysPostMapper, SysPostEntity>{
	
	@Autowired
	private SysDeptService deptService;
	
	/**
	 * 根据用户id获取岗位
	 */
	public List<SysPostEntity> getPostListByUserId(Integer userId){
		return this.baseMapper.getPostListByUserId(userId);
	}
	
	/**
	 * 根据部门id获取其岗位id及其子部门的岗位id
	 */
	public List<Integer> getPostIdByDeptId(Integer deptId){
		List<SysDeptEntity> deptIdsList = deptService.getDeptAllChildrenIdById(deptId);
		String deptIds = deptIdsList.stream().map(entity->String.valueOf(entity)).collect(Collectors.joining(","))+","+deptId;
		return this.baseMapper.selectList(new QueryWrapper<SysPostEntity>().eq("status", 0).in("deptId", deptIds)).stream().map(entity->entity.getId()).collect(Collectors.toList());
	}
}
